home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
016a
/
xtclock2.zip
/
GETCLOCK.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
2KB
|
94 lines
/* Program GETCLOCK */
/* Version 2.0 */
/* Compiler MIX Power C */
/* Author Gerald M. Vrooman */
/* Date 07/30/91 */
/* GETCLOCK can be used with an XT clock card to initialize DOS */
/* time and date when booting up. The Multi I/O card that this */
/* routine was designed for uses the following ports: */
/* &h242 - Second */
/* &h243 - Minute */
/* &h244 - Hour */
/* &h246 - Day */
/* &h247 - Month */
/* &h249 - year */
/* If necessary this program can be modified for cards with */
/* different port addresses merely by changing the arguments */
/* used with inportb() . */
#include <stdio.h>
#include <dos.h>
#include <stdlib.h>
main(int argc,char *argv[])
{
int year,month,day,hour,minute,second;
char buffer[5];
struct {
unsigned char ti_min;
unsigned char ti_hour;
unsigned char ti_hund;
unsigned char ti_sec;
} timebuf;
struct {
int da_year;
char da_day;
char da_mon;
} datebuf;
printf("\nGETCLOCK Written 1991 by Gerald M. Vrooman\n\n");
year = bcdint(inportb(0x249));
if (year >= 80)
datebuf.da_year = year + 1900;
else
datebuf.da_year = year + 2000;
month = bcdint(inportb(0x247));
datebuf.da_mon = month;
day = bcdint(inportb(0x246));
datebuf.da_day = day;
setdate(&datebuf);
hour = bcdint(inportb(0x244));
timebuf.ti_hour = hour;
minute = bcdint(inportb(0x243));
timebuf.ti_min = minute;
second = bcdint(inportb(0x242));
timebuf.ti_sec = second;
timebuf.ti_hund = 0;
settime(&timebuf);
}
/* bcdint converts binary coded decimal byte to integer */
bcdint(bcd)
int bcd;
{
int tens,ones;
tens = bcd / 16;
ones = bcd % 16;
return(tens * 10 + ones);
}